//
//  HomefansViewController.m
//  LiveStar
//
//  Created by 漪珊 on 2016/12/9.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "HomefansViewController.h"
#import "MessageViewController.h"
#import "HomeSearchViewController.h"
#import "MoreLivingViewController.h"
#import "HomeSearchViewController.h"
#import "AboutViewController.h"
#import "CallStarViewController.h"
#import "StarPredictViewController.h"
#import "StarVideoViewController.h"
#import "BuyViewController.h"
#import "WatchViewController.h"
#import "StarLivingListCell.h"
#import "CallStarLeavewordViewController.h"
#import "FHomePredictCell.h"
#import "CallStarHomeCell.h"
#import "WatchLiveTipView.h"
#import "AddStarView.h"
#import "QZHSearchBar.h"
#import "FHomeTopView.h"
#import "FHomeHeader.h"
#import "FHomeFooter.h"
#import "HomeLayout.h"
#import "LiveListModel.h"
#import "PredictListModel.h"
#import "RechargeListModel.h"

@interface HomefansViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,FHomeTopViewDelegate,WatchLiveTipViewDelegate,CallStarCellDelegate,AddStarViewDelegate>
{
    NSMutableArray *_livingListArray;
    NSMutableArray *_predictListArray;
    NSMutableArray *_callStarListArray;
    NSMutableArray *_videoListArray;
    /**
      兑换加星type数组
     */
    NSMutableArray *_rechargeListArray;
}

@property (weak, nonatomic) IBOutlet UICollectionView *homeCollectionView;
@property (nonatomic, strong) HomeLayout *flowLayout;
/**
   新消息提醒
 */
@property (nonatomic, strong) UIView *msgNotice;
/**
   账户是否充足
 */
@property (nonatomic, assign) BOOL BalanceTag;
@property (nonatomic, strong) WatchLiveTipView *watchTipView;

@property (nonatomic, strong) AddStarView *addStarView;
@property (nonatomic, copy) NSString *balance;
@property (nonatomic, assign) int tag;
@end

@implementation HomefansViewController
static NSString *starLivingListCellID = @"StarLivingListCellID";
static NSString *fHomePredictCellID = @"fHomePredictCellID";
static NSString *callStarHomeCellID = @"callStarHomeCellID";
static NSString *fHomeTopView = @"fHomeTopView";
static NSString *fHomeHeader = @"fHomeHeader";
static NSString *fHomeFooter = @"fHomeFooter";

#pragma mark -- 首页网络请求
- (void)HomeDataRequest {
    NSDictionary *dict = @{
                       @"udid":User_ID,
                       @"token":TOKEN,
                       @"page":@"1",
                       @"live":@"6",
                       @"shout":@"3",
                       @"advance":@"3",
                       @"play":@"4"
                       };
    NSString *urlString = [TEST_URL stringByAppendingString:kFHomeList];
    [NetworkTools postReqeustWithParams:dict UrlString:urlString successBlock:^(id responseObject) {
        [self endRefresh];
        if ([responseObject[@"code"] intValue] == 200) {
            if (_livingListArray.count>0) {
                [_livingListArray removeAllObjects];
            }
            if (_predictListArray.count>0) {
                [_predictListArray removeAllObjects];
            }
            if (_callStarListArray.count>0) {
                [_callStarListArray removeAllObjects];
            }
            if (_videoListArray.count>0) {
                [_videoListArray removeAllObjects];
            }
            NSArray *predictArr = responseObject[@"data"][@"advance"][@"list"];
            NSArray *videoArr = responseObject[@"data"][@"play"][@"list"];
            NSArray *liveArr = responseObject[@"data"][@"live"][@"list"];
            NSArray *callArr = responseObject[@"data"][@"shout"][@"list"];
            for (NSDictionary *liveDict in liveArr) {
                LiveListModel *model = [[LiveListModel alloc] initWithDict:liveDict];
                [_livingListArray addObject:model];
            }
            for (NSDictionary *predictDict in predictArr) {
                PredictListModel *model = [[PredictListModel alloc] initWithDict:predictDict];
                [_predictListArray addObject:model];
            }
            for (NSDictionary *callDict in callArr) {
                CallStarModel *model = [[CallStarModel alloc] initWithDict:callDict];
                [_callStarListArray addObject:model];
            }

            for (NSDictionary *videoDict in videoArr) {
                LiveListModel *model = [[LiveListModel alloc] initWithDict:videoDict];
                [_videoListArray addObject:model];
            }
            [self.homeCollectionView reloadData];
        }
    } failureBlock:^(NSError *error) {
        [self endRefresh];
    } showHUD:NO];
}
// watchTipView
- (void)creatWatchTipViewWith:(BOOL)BalanceTag LiveListModel:(LiveListModel*)listModel Balance:(NSString *)balance {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.watchTipView = [[NSBundle mainBundle] loadNibNamed:@"WatchLiveTipView" owner:self options:nil].lastObject;
    self.watchTipView.delegate = self;
    self.watchTipView.livelistModel = listModel;
    self.watchTipView.balance.text = [NSString stringWithFormat:@"您的账户余额 : %@L币",balance];
    [window addSubview:self.watchTipView];
    self.watchTipView.backgroundColor = kRGB(0, 0, 0, 0.6);
    [self.watchTipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(window);
    }];
    
    //设置余额不足的隐藏
    if (self.BalanceTag == YES) {
        self.watchTipView.NoPayNotice.hidden = YES;
        [self.watchTipView.watchBtn setTitle:@"观看直播" forState:UIControlStateNormal];
    } else {
        self.watchTipView.NoPayNotice.hidden = NO;
        [self.watchTipView.watchBtn setTitle:@"立即购买" forState:UIControlStateNormal];
    }
}


#pragma mark -- 首页消息通知
- (void)MessageCenterRequest {
    NSDictionary *dict = @{@"udid":User_ID,
                           @"token":TOKEN
                           };
    NSString *urlString = [TEST_URL stringByAppendingString:KMsgURdNum];
    [NetworkTools postReqeustWithParams:dict UrlString:urlString successBlock:^(id responseObject) {
        if ([responseObject[@"code"] intValue] == 200) {
            int num = [responseObject[@"data"][@"num"] intValue];
            if (num > 0) {
                self.msgNotice.hidden = NO;
            } else {
                self.msgNotice.hidden = YES;
            }
        }
    } failureBlock:^(NSError *error) {
        
    } showHUD:NO];
}

#pragma mark -- 订阅网络请求
- (void)BookLivingRequestWithPredictID:(NSString *)prdictId IndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dict = @{@"udid":User_ID,
                           @"token":TOKEN,
                           @"follow":prdictId,
                           };
    NSString *urlString = [TEST_URL stringByAppendingString:kBookPredict];
    [NetworkTools postReqeustWithParams:dict UrlString:urlString successBlock:^(id responseObject) {
        if ([responseObject[@"code"] integerValue] == 200) {
            PredictListModel *model = _predictListArray[indexPath.row];
            model.l_booked = KString(responseObject[@"data"][@"number"]);
            model.booked = responseObject[@"data"][@"status"];
            [self.homeCollectionView reloadItemsAtIndexPaths:@[indexPath]];
        }
    } failureBlock:^(NSError *error) {
        
    } showHUD:NO];
}
#pragma mark -- 观看直播
// 查询账户余额接口
- (void)BalanceRequestWithLiveListModel:(LiveListModel *)listModel {
    NSDictionary *dict = @{
                           @"udid":User_ID,
                           @"token":TOKEN
                           };
    NSString *urlString = [TEST_URL stringByAppendingString:kBalance];
    [self showHUDInView:self.view title:nil];
    [NetworkTools postReqeustWithParams:dict UrlString:urlString successBlock:^(id responseObject) {
        [self hideHUD];
        NSString *balance = responseObject[@"data"][@"u_balance"];
        if ([balance intValue] < [listModel.s_price intValue]) {//余额不足
            self.BalanceTag = NO;
        } else {//余额充足
            self.BalanceTag = YES;
        }
        [self creatWatchTipViewWith:self.BalanceTag LiveListModel:listModel Balance:balance];
    } failureBlock:^(NSError *error) {
        [self hideHUD];
    } showHUD:NO];
}

// 支付观看看直播费用
- (void)payLiveWithChannel:(NSString *)channel Price:(NSString *)price S_uid:(NSString *)s_uid {
    NSDictionary *paramDic = @{
                               @"udid":User_ID,
                               @"token":TOKEN,
                               @"channel":channel,
                               @"price":price
                               };
    NSString *urlString = [TEST_URL stringByAppendingString:kPayLive];
    [NetworkTools postReqeustWithParams:paramDic UrlString:urlString successBlock:^(id responseObject) {
        [self PulladdressRequestWithRoomId:channel S_uid:s_uid];
    } failureBlock:^(NSError *error) {
        
    } showHUD:NO];
}
//获取观看直播地址
- (void)PulladdressRequestWithRoomId:(NSString *)roomid S_uid:(NSString *)s_uid {
    NSDictionary *dic = @{
                          @"udid":User_ID,
                          @"token":TOKEN,
                          @"channel":roomid,
                          @"status":@"1" //1表示进入直播间
                          };
    NSString *urlString = [TEST_URL stringByAppendingString:kWatchlive];
    [NetworkTools postReqeustWithParams:dic UrlString:urlString successBlock:^(id responseObject) {
        NSString *pullUrl = responseObject[@"data"][@"url"][1];
        
        WatchViewController *watchVc = [[WatchViewController alloc] init];
        watchVc.roomid = roomid;
        watchVc.chatroomid = roomid;
        watchVc.s_uid = s_uid;
        watchVc.pullUrl = pullUrl;
        [self presentViewController:watchVc animated:YES completion:nil];
        
    } failureBlock:^(NSError *error) {
        [self showTitle:@"连接服务器失败"];
    } showHUD:NO];
}


#pragma mark -- 呼唤明星
- (void)CallStarRequestWithShoutID:(NSString *)shoutId IndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dict = @{@"udid":User_ID,
                           @"token":TOKEN,
                           @"shout":shoutId
                           };
    NSString *urlString = [TEST_URL stringByAppendingString:kCallStar];
    [self showHUDInView:self.view title:nil];
    [NetworkTools postReqeustWithParams:dict UrlString:urlString successBlock:^(id responseObject) {
        [self hideHUD];
        if ([responseObject[@"code"] intValue] == 200) {
            CallStarModel *model = _callStarListArray[indexPath.row];
            model.booked = responseObject[@"data"][@"status"];
            model.s_number = responseObject[@"data"][@"number"];
            [self.homeCollectionView reloadItemsAtIndexPaths:@[indexPath]];
        } else if ([responseObject[@"code"] intValue] == 400) { //次数不足
            [self reChargeListRequest];
        }
    } failureBlock:^(NSError *error) {
        [self hideHUD];
    } showHUD:NO];
}

//兑换加星次数列表
- (void)reChargeListRequest {
    NSDictionary *dict = @{@"udid":User_ID,
                           @"token":TOKEN,
                           @"type":@"250"
                           };
    NSString *urlString = [TEST_URL stringByAppendingString:kGifList];\
    [NetworkTools postReqeustWithParams:dict UrlString:urlString successBlock:^(id responseObject) {
        if ([responseObject[@"code"] intValue] == 200) {
            self.balance = responseObject[@"data"][@"u_balance"];
            NSArray *array = responseObject[@"data"][@"list"];
            for (NSDictionary *rechargeDict in array) {
                RechargeListModel *model = [[RechargeListModel alloc] initWithDict:rechargeDict];
                [_rechargeListArray addObject:model];
            }
            [self reChargeNumsView];
        }
    } failureBlock:^(NSError *error) {
        
    } showHUD:NO];
}

//兑换次数
- (void)exchangeNumsRequestWithGoodId:(NSString *)goodsId Amount:(NSString *)amount {
    NSDictionary *dict = @{@"udid":User_ID,
                           @"token":TOKEN,
                           @"type":@"40",
                           @"cid":goodsId,
                           @"amount":amount
                           };
    NSString *urlString = [TEST_URL stringByAppendingString:kRechargePay];
    [NetworkTools postReqeustWithParams:dict UrlString:urlString successBlock:^(id responseObject) {
        if ([responseObject[@"code"] intValue] == 200) {
            [self closeAddStarTipView];
            [self showTitle:responseObject[@"data"][@"message"]];
        }
    } failureBlock:^(NSError *error) {
        
    } showHUD:NO];
}

#pragma mark -- 充值View
- (void)reChargeNumsView {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.addStarView = [[NSBundle mainBundle] loadNibNamed:@"AddStarView" owner:self options:nil].lastObject;
    self.addStarView.delegate = self;
    self.addStarView.balanceLabel.text = [NSString stringWithFormat:@"账户余额 : %@",KString(self.balance)] ;
    self.addStarView.dataArray = [NSArray arrayWithArray:_rechargeListArray];
    [window addSubview:self.addStarView];
    self.addStarView.backgroundColor = kRGB(0, 0, 0, 0.6);
    [self.addStarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(window);
    }];
}

#pragma mark -- AddStarViewDelegate
- (void)closeAddStarTipView {
    [self.addStarView removeFromSuperview];
}

//兑换
- (void)exchangeNums {
    RechargeListModel *model = _rechargeListArray[self.tag];
    [self exchangeNumsRequestWithGoodId:model.cid Amount:model.c_value];
}
//选择类型
- (void)selectedTypeWithTag:(int)tag {
    self.tag = tag;
    switch (tag) {
        case 0:{
        }
            break;
        case 1:{
        }
            break;
        case 2:{
        }
            break;
        case 3:{
        }
            break;
            
        default:
            break;
    }
}


#pragma mark -- WatchTipViewDelegate

- (void)closeTipView {
    [self.watchTipView removeFromSuperview];
}

- (void)buyClickWithTipView:(WatchLiveTipView *)watchtipView LiveListModel:(LiveListModel*)liveListModel {
    if (self.BalanceTag == NO) {//去购买芝麻
        [self.watchTipView removeFromSuperview];
        BuyViewController *buyVC = [[BuyViewController alloc] init];
        buyVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:buyVC animated:YES];
    } else {//观看直播
        [self.watchTipView removeFromSuperview];
        [self payLiveWithChannel:liveListModel.l_channel Price:liveListModel.s_price S_uid:liveListModel.l_udid];
    }
}


- (void)viewWillDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self HomeDataRequest];
    [self MessageCenterRequest];
    [self setUpUI];
    [self setUpNav];
}
/**
 *  停止刷新
 */
-(void)endRefresh{
    [self.homeCollectionView.mj_header endRefreshing];
    [self.homeCollectionView.mj_footer endRefreshing];
}


#pragma mark -- UI Nav
- (void)setUpUI {
    self.view.backgroundColor = [UIColor whiteColor];
   _livingListArray = [NSMutableArray arrayWithCapacity:1];
    _predictListArray = [NSMutableArray arrayWithCapacity:1];
    _callStarListArray = [NSMutableArray arrayWithCapacity:1];
    _videoListArray = [NSMutableArray arrayWithCapacity:1];
    _rechargeListArray = [NSMutableArray arrayWithCapacity:1];
    self.flowLayout = [[HomeLayout alloc] init];
    [self.flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    self.flowLayout.livingCount = 4;
    self.flowLayout.predictCount = 3;
    self.flowLayout.callStarCount = 3;
    self.flowLayout.videoCount = 4;
    self.homeCollectionView.collectionViewLayout = self.flowLayout;
    self.homeCollectionView.delegate = self;
    self.homeCollectionView.dataSource = self;
    self.homeCollectionView.backgroundColor = [UIColor whiteColor];
    self.homeCollectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self HomeDataRequest];
    }];
    [self.homeCollectionView registerNib:[UINib nibWithNibName:@"StarLivingListCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:starLivingListCellID];
    [self.homeCollectionView registerNib:[UINib nibWithNibName:@"FHomePredictCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:fHomePredictCellID];
    [self.homeCollectionView registerNib:[UINib nibWithNibName:@"CallStarHomeCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:callStarHomeCellID];
    [self.homeCollectionView registerNib:[UINib nibWithNibName:@"FHomeTopView" bundle:[NSBundle mainBundle]] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:fHomeTopView];
    [self.homeCollectionView registerNib:[UINib nibWithNibName:@"FHomeHeader" bundle:[NSBundle mainBundle]] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:fHomeHeader];
    [self.homeCollectionView registerNib:[UINib nibWithNibName:@"FHomeFooter" bundle:[NSBundle mainBundle]] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:fHomeFooter];
}


- (void)setUpNav {
    //关于我们
    UIButton *aboutOurBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 23, 23)];
    [aboutOurBtn addTarget:self action:@selector(AboutOurClick:) forControlEvents:UIControlEventTouchUpInside];
    [aboutOurBtn setImage:[UIImage imageNamed:@"About"] forState:UIControlStateNormal];
    UIBarButtonItem *leftBtnItem1 = [[UIBarButtonItem alloc] initWithCustomView:aboutOurBtn];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
    negativeSpacer.width = - 12;
    NSArray *leftItemsArray = @[negativeSpacer,leftBtnItem1];
    self.navigationItem.leftBarButtonItems = leftItemsArray;
    //标题
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 84, 20)];
    imageview.image = kSET_IMAGE(@"HomeTitle");
    self.navigationItem.titleView = imageview;
    //搜索 消息
    UIView *messageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 23, 23)];
    self.msgNotice = [[UIView alloc] init];
    self.msgNotice.backgroundColor = [UIColor redColor];
    kViewRadius(self.msgNotice, 7.0f/2);
    [messageView addSubview:self.msgNotice];
    [self.msgNotice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(messageView.mas_top).offset(-1);
        make.right.equalTo(messageView.mas_right).offset(2);
        make.height.width.mas_equalTo(7);
    }];
    UIButton *messageBtn = [[UIButton alloc] init];
    [messageView addSubview:messageBtn];
    [messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(messageView);
    }];
    [messageBtn addTarget:self action:@selector(MessageCenterClick:) forControlEvents:UIControlEventTouchUpInside];
    [messageBtn setImage:[UIImage imageNamed:@"messagecenter"] forState:UIControlStateNormal];
    UIBarButtonItem *rightBtnItem = [[UIBarButtonItem alloc] initWithCustomView:messageView];
    
    
    UIButton *searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 26, 26)];
    [searchBtn addTarget:self action:@selector(SearchClick:) forControlEvents:UIControlEventTouchUpInside];
    [searchBtn setImage:[UIImage imageNamed:@"Search"] forState:UIControlStateNormal];
    UIBarButtonItem *rightBtnItem1 = [[UIBarButtonItem alloc] initWithCustomView:searchBtn];
    UIBarButtonItem *negativeSpacer1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
    negativeSpacer1.width = - 10;
    UIBarButtonItem *negativeSpacer2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
    negativeSpacer2.width = 23;
    NSArray *rightItemsArray = @[negativeSpacer1,rightBtnItem,negativeSpacer2,rightBtnItem1];
    [self.navigationItem setRightBarButtonItems:rightItemsArray];
}
#pragma mark -- collectonView Delegate DataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 4;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return _livingListArray.count;
            break;
        case 1:
            return _predictListArray.count;
            break;
        case 2:
            return _callStarListArray.count;
            break;
        case 3:
            return _videoListArray.count;
            break;
        default:
            break;
    }
    return 0;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:case 3:{//直播 回放
            StarLivingListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:starLivingListCellID forIndexPath:indexPath];
            if (indexPath.section == 0) {
                cell.livingStatus.text = @" 直播中 ";
                LiveListModel *model = _livingListArray[indexPath.row];
                cell.livelistModel = model;
            } else {
                cell.livingStatus.text = @" 回放 ";
            }
            return cell;
        }
            break;
        case 1:{//预告
            FHomePredictCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:fHomePredictCellID forIndexPath:indexPath];
            PredictListModel *model = _predictListArray[indexPath.row];
            cell.predictModel = model;
            cell.bookLive = ^(){
                [self BookLivingRequestWithPredictID:model.l_id IndexPath:indexPath];
            };
            return cell;
        }
            break;
        case 2:{
            CallStarHomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:callStarHomeCellID forIndexPath:indexPath];
            cell.delegate = self;
            CallStarModel *model = _callStarListArray[indexPath.row];
            cell.starOrderLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row+1];
            cell.callStarModel = model;
            cell.callStar = ^{
                [self CallStarRequestWithShoutID:KString(model.sid) IndexPath:indexPath];
            };
            return cell;
        }
        default:
            break;
    }
    return nil;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    UICollectionReusableView *reusableView;
    if (kind == UICollectionElementKindSectionHeader) {
        if (indexPath.section == 0) {
            FHomeTopView *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:fHomeTopView forIndexPath:indexPath];
            header.delegate = self;
            reusableView = header;
            return reusableView;
        }
        FHomeHeader *header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:fHomeHeader forIndexPath:indexPath];
        if (indexPath.section == 1) {
            header.tipImgView.image = kSET_IMAGE(@"Predict_Title");
        } else if (indexPath.section == 2) {
            header.tipImgView.image = kSET_IMAGE(@"CallStar_Title");
        } else if (indexPath.section == 3) {
            header.tipImgView.image = kSET_IMAGE(@"Video_Title");
        }
        reusableView = header;
        return reusableView;
    } else {
        FHomeFooter *footer = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:fHomeFooter forIndexPath:indexPath];
        switch (indexPath.section) {
            case 0:
                [footer.lookmoreBtn setTitle:@"全部直播" forState:UIControlStateNormal];
                break;
            case 1:
                [footer.lookmoreBtn setTitle:@"全部预告" forState:UIControlStateNormal];
                break;
            case 2:
                [footer.lookmoreBtn setTitle:@"全部呼唤" forState:UIControlStateNormal];
                break;
            case 3:
                [footer.lookmoreBtn setTitle:@"全部回放" forState:UIControlStateNormal];
                break;
                
            default:
                break;
        }
        __weak typeof(self) WeakSelf = self;
        footer.lookMore = ^(){
            switch (indexPath.section) {
                case 0:{
                    MoreLivingViewController * moreLivingVC = [MoreLivingViewController new];
                    [WeakSelf.navigationController pushViewController:moreLivingVC animated:YES];
                }
                    break;
                case 1:{
                    StarPredictViewController *predictVC = [StarPredictViewController new];
                    [self.navigationController pushViewController:predictVC animated:YES];
                }
                    break;
                case 2:{
                    CallStarViewController *callstarVC = [CallStarViewController new];
                    [self.navigationController pushViewController:callstarVC animated:YES];
                }
                    break;
                case 3:{
                    StarVideoViewController *videoVC = [StarVideoViewController new];
                    [self.navigationController pushViewController:videoVC animated:YES];
                }
                    break;
                    
                default:
                    break;
            }
           
        };
        reusableView = footer;
        return reusableView;
    }
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    switch (section) {
        case 0:{
            return CGSizeMake(kSCREEN_WIDTH, 122);
        }
            break;
        case 1:{
            if (_predictListArray.count) {
                return CGSizeMake(kSCREEN_WIDTH, 56);
            }
            return CGSizeZero;
        }
            break;
        case 2:{
            if (_callStarListArray.count) {
                return CGSizeMake(kSCREEN_WIDTH, 56);
            }
            return CGSizeZero;
        }
            break;
        case 3:{
            if (_videoListArray.count) {
                return CGSizeMake(kSCREEN_WIDTH, 56);
            }
            return CGSizeZero;
        }
            break;
            
        default:
            break;
    }
    return CGSizeZero;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    switch (section) {
        case 0:{
            if (_livingListArray.count) {
                return CGSizeMake(kSCREEN_WIDTH, 40);
            }
            return CGSizeZero;
        }
            break;
        case 1:{
            if (_predictListArray.count) {
                return CGSizeMake(kSCREEN_WIDTH, 40);
            }
            return CGSizeZero;
        }
            break;
        case 2:{
            if (_callStarListArray.count) {
               return CGSizeMake(kSCREEN_WIDTH, 40);
            }
            return CGSizeZero;
        }
            break;
        case 3:{
            if (_videoListArray.count) {
                return CGSizeMake(kSCREEN_WIDTH, 40);
            }
            return CGSizeZero;
        }
            break;
            
        default:
            break;
    }
    return CGSizeZero;
}

#pragma mark -- collectionViewFlowLayoutDelegate 
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 1) {
        return CGSizeMake(kSCREEN_WIDTH, 115);
    } else if (indexPath.section == 2) {
        return CGSizeMake(kSCREEN_WIDTH, 66);
    }
    return CGSizeMake((kSCREEN_WIDTH - 40)/2, (kSCREEN_WIDTH-40)/2+30);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    if (section == 1||section == 2) {
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
    return UIEdgeInsetsMake(0, 15, 10, 15);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    switch (indexPath.section) {
        case 0:{
            LiveListModel *listModel = _livingListArray[indexPath.row];
            //查询账户余额
            [self BalanceRequestWithLiveListModel:listModel];
        }
            break;
        case 1:
            break;
        case 2:
            break;
        case 3:
            break;
            
        default:
            break;
    }
}

#pragma mark --  关于我们 / 消息中心 / 搜索
- (void)AboutOurClick:(UIButton *)sender {
    AboutViewController *aboutVC = [[AboutViewController alloc] init];
    [self.navigationController pushViewController:aboutVC animated:YES];
}
- (void)MessageCenterClick:(UIButton *)sender {
    MessageViewController *messageVc = [MessageViewController new];
    messageVc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:messageVc animated:YES];
}

- (void)SearchClick:(UIButton *)sender {
    HomeSearchViewController *searchVC = [HomeSearchViewController new];
    [self.navigationController pushViewController:searchVC animated:YES];
}

#pragma mark -- 顶部按钮响应事件 FHomeTopViewDelegate
- (void)TopActionWithTag:(NSString *)tag {
    if ([tag isEqualToString:@"1"]) {//环保行动
        
    } else {//呼唤明星
        CallStarViewController *callstarVC = [CallStarViewController new];
        [self.navigationController pushViewController:callstarVC animated:YES];
    }
}

#pragma mark --  CallStarCellDelegate
- (void)callStarLeavewordListWithCell:(CallStarHomeCell *)callStarHomeCell {
    NSIndexPath *indexPath = [self.homeCollectionView indexPathForCell:callStarHomeCell];
    CallStarModel *model = _callStarListArray[indexPath.row];
    CallStarLeavewordViewController *leaveWordVC = [[CallStarLeavewordViewController alloc] init];
    leaveWordVC.cid = model.sid;
    [self.navigationController pushViewController:leaveWordVC animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
